package com.pen;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pen.shardingjdbc.ShardJdbcDemoApplication;
import com.pen.shardingjdbc.entity.Udict;
import com.pen.shardingjdbc.entity.User;
import com.pen.shardingjdbc.mapper.UdictMapper;
import com.pen.shardingjdbc.mapper.UserMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * 分表分库测试
 * 模型：数据库-m1，m2
 * 每个数据库分表有：d1，d2两张表
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ShardJdbcDemoApplication.class)
public class ShardingJdbcDemoTest4 {
    @Autowired
    UdictMapper udictMapper;

    @Test
    public void save() {
        Udict udict1 = Udict.builder().status("1").value("你好").build();
        Udict udict2 = Udict.builder().status("1").value("你好").build();
        Udict udict3 = Udict.builder().status("1").value("你好").build();
        udictMapper.insert(udict1);
        udictMapper.insert(udict2);
        udictMapper.insert(udict3);
    }

    @Test
    public void updateById() {
        Udict udict1 = Udict.builder().status("1").value("你我是修改好").dictId(1398362150888235009L).build();
        udictMapper.updateById(udict1);
    }
    @Test
    public void findById() {
        Udict udict = udictMapper.selectById(1398321068901040129L);
        System.out.println(udict);
    }

    @Test
    public void findByUserId() {
        QueryWrapper<Udict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dictId", 12);


        List<Udict> courses = udictMapper.selectList(queryWrapper);
        for (Udict user : courses) {
            System.out.println(user.toString());
        }
    }

}
